package com.game.server.message.proto.execute;

import com.comm.ISession;
import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubMemberInfoDao;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYclubPlayerUpdateBonusShareReq;
import com.game.server.message.proto.out.XYclubPlayerUpdateBonusShareRsp;

public class XYclubPlayerUpdateBonusShareReq extends AbstractXYclubPlayerUpdateBonusShareReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null && client.checkClick(msgcode)) {
            XYclubPlayerUpdateBonusShareRsp rsp = new XYclubPlayerUpdateBonusShareRsp();
            rsp.setIsok(1);
            if (this.proportion >= 10 && (this.proportion % 10) == 0 && this.proportion <= 100) {
                XyClubInfo xyClubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
                if (xyClubInfo != null) {
                    XyClubMemberInfo myMemberInfo = xyClubInfo.getPlayer().get(client.getUserId());
                    if (myMemberInfo != null && (myMemberInfo.getIsManager() == 1 || myMemberInfo.getIsManager() == 2)) {
                        XyClubMemberInfo toMemberInfo = xyClubInfo.getPlayer().get(this.uid);
                        if (toMemberInfo != null && toMemberInfo.getIsAccessory() == 1) {
                            int updateCount = XyClubMemberInfoDao.updateBonusShare(toMemberInfo.getId(), this.proportion);
                            if (updateCount > 0) {
                                toMemberInfo.setBonus_share(this.proportion);
                                rsp.setIsok(0);
                                rsp.setProportion(this.proportion);
                            }
                        }
                    }
                }
            }
            client.Send(rsp);
        }
    }

}
